import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/14 9:02
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    int ans = -1;
    int rootValue;

    public int findSecondMinimumValue(TreeNode root) {
        ans = -1;
        rootValue = root.val;
        dfs(root);
        return ans;
    }

    public void dfs(TreeNode node) {
        if (node == null) {
            return;
        }
        if (ans != -1 && node.val >= ans) {
            return;
        }
        if (node.val > rootValue) {
            // 即 rootValue < node.val < ans
            ans = node.val;
        }
        dfs(node.left);
        dfs(node.right);
    }

}
